<%@include file="../../generic/inc/head.jsp"%>

<%@ page import="fr.mywiki.view.web.struts.action.version.VersionListAction" %>
<%@ page import="fr.mywiki.view.web.struts.form.version.VersionListForm" %>
<%@ page import="fr.mywiki.model.valueobjects.VersionLite" %>

<script>
function displayVersion(id) {
	document.forms["versionListForm"].method.value='displayVersion';
	document.forms["versionListForm"].<%=VersionListAction.VERSION_ID%>.value=id;
	document.forms["versionListForm"].submit();
}

function rollback(id) {
	document.forms["versionListForm"].method.value='rollback';
	document.forms["versionListForm"].<%=VersionListAction.VERSION_ID%>.value=id;
	document.forms["versionListForm"].submit();
}

function compareVersions() {
	document.forms["versionListForm"].method.value='compare';
	document.forms["versionListForm"].submit();
}
</script>

<div id="mainPanel">
	<html:form action="versionList">
		<html:hidden property="method" value="" />
		<html:hidden property="<%=VersionListAction.VERSION_ID%>" value="" />

		<a href="javascript:compareVersions();">
			<bean:message key="version.compare"/>
		</a>
		
		<table>
<%
	VersionListForm form = (VersionListForm) request.getSession().getAttribute("versionListForm");
	VersionLite first = (VersionLite) (form.getVersionList()).get(0);
	VersionLite secund = (VersionLite) (form.getVersionList()).get(1);
	Iterator itVersions = form.getVersionList().iterator();
	while(itVersions.hasNext()) {
		VersionLite version = (VersionLite) itVersions.next();
%>
			<tr>
				<td>
<%
		if(version.isCurrent()) {
%>
					<html:img srcKey="version.current" bundle="IMAGES_RESSOURCE_KEY"/>
<%
		}
%>
				</td>
				<td>
					<bean:message key="version.number"/>&nbsp;
					<%=version.getNumber()%>
				</td>
				<td>
<%
		if(version.getId().equals(secund.getId())) {
%>
					<input type=radio name=from value="<%=version.getId()%>" checked>
<%
		} else {
%>
					<input type=radio name=from value="<%=version.getId()%>">
<%
		}
%>
				</td>
				<td>
<%
		if(version.getId().equals(first.getId())) {
%>
					<input type=radio name=to value="<%=version.getId()%>" checked>
<%
		} else {
%>
					<input type=radio name=to value="<%=version.getId()%>">
<%
		}
%>
				</td>
				<td>
					<a href="javascript:displayVersion(<%=version.getId()%>);">
						<bean:message key="version.display"/>
					</a>
				</td>
				<td>
<%
		if(!version.isCurrent()) {
%>
						<a href="javascript:rollback(<%=version.getId()%>);">
							<bean:message key="version.rollback"/>
						</a>
<%
		}
%>
				</td>
				<td>&nbsp;-&nbsp;</td>
				<td><%=version.getAuthor()%></td>
				<td>(<%=version.getDate()%>)</td>
			</tr>
<%
	}
%>
		</table>
	</html:form>
	<html:img srcKey="version.current" bundle="IMAGES_RESSOURCE_KEY"/>&nbsp;:&nbsp;
	<bean:message key="version.current"/>
</div>

<%@include file="../../generic/inc/foot.jsp"%>
